<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>组织列表</title>
    <th:block layout:fragment="head-include">
    </th:block>
</head>


<body>
<section class="content-header">
	      <row>
	         <ol class="breadcrumb">
		        <li><a href="#"><i class="fa fa-home"></i> 首页</a></li>
		        <li class="active"><i class="fa  fa-map-marker"></i>组织管理</li>
		      </ol>
	      </row>    
</section>
<section layout:fragment="content" class="content">

    <style>

    </style>
    <div class="col-md-12 ">
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">编辑组织</h3>&nbsp;&nbsp;&nbsp;
				<a href="javascript:orgDevList();"><i class="fa fa-cubes"></i> 挂靠设备</a></li>
            </div>
            <div class="form-horizontal">
                <div class="box-body">
                    <form method="post" id="editModalForms">
                        <div class="form-group">
                            <input type="text" name="id" th:value="${org.id}" style="display:none"/>
                            <input type="text" name="orgid" th:value="${org.orgid}" style="display:none"/>
                            <input type="text" th:if=${org.parent} name="parentid" th:value="${org.parent.id}"
                                   style="display:none"/>
                            <label class="col-sm-2 control-label">组织编号 :</label>

                            <div class="col-sm-9 " style="padding-top:6px" th:text="${org.orgid}"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">组织名称 :</label>

                            <div class="col-sm-9"><input name="orgName" type="text" th:value="${org.orgName}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">中心点X :</label>

                            <div class="col-sm-9"><input name="centrex" type="text" th:value="${org.centrex}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">中心点Y :</label>

                            <div class="col-sm-9"><input name="centrey" type="text" th:value="${org.centrey}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">联系人 : </label>

                            <div class="col-sm-9"><input name="linkMain" type="text" th:value="${org.linkMain}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">联系人电 话 :</label>

                            <div class="col-sm-9"><input name="linkPhone" type="text" th:value="${org.linkPhone}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">负责人 : </label>

                            <div class="col-sm-9"><input name="principal" type="text" th:value="${org.principal}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">负责人电 话 : </label>

                            <div class="col-sm-9"><input name="principalPhone" type="text"
                                                         th:value="${org.principalPhone}" class="form-control orgText">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注 : </label>

                            <div class="col-sm-9"><input name="remark" type="text" th:value="${org.remark}"
                                                         class="form-control orgText"></div>
                        </div>
                        <div class="box-footer text-center">
                            <a class="btn btn-box-tool ">
                                <button type="submit" class="btn btn-primary btnPrimary"
                                        form="editModalForms">确定
                                </button>
                                <!-- <button type="button" class="btn btn-danger orgDelete" th:attr="delId=${org.orgid}">删除</button> -->
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- 修改保存 -->
    <div class="modal fade" tabindex="-1" role="dialog" id="saveModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"
                                                                                                      class="fa fa-times"></span>
                    </button>
                    <h4 class="modal-title">提示：</h4>
                </div>
                <div class="modal-body">
                    <h4 style="margin-left:70px">是否保存？</h4>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary " data-dismiss="modal" id="saveTrue">确定</button>
                    <button type="button" class="btn btn-default" id="saveCancel">取消</button>
                </div>
            </div>
        </div>
    </div>

</section>
<script>
    $(function () {
        /* 编辑组织 */
        $('#editModalForms').bootstrapValidator({
            excluded: [],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {

                orgName: {
                    validators: {
                        notEmpty: {
                            message: '请输入组织名称'
                        }
                    }
                },
                centrex: {
                    validators: {
                        notEmpty: {
                            message: '请输入中心点 X'
                        },
                        regexp: {
                            regexp: /^[0-9]+([.]{1}[0-9]+){0,1}$/,
                            message: '请输入正确坐标'
                        }
                    }
                },
                centrey: {
                    validators: {
                        notEmpty: {
                            message: '请输入中心点 Y'
                        },
                        regexp: {
                            regexp: /^[0-9]+([.]{1}[0-9]+){0,1}$/,
                            message: '请输入正确坐标'
                        }
                    }
                },
                linkMain: {
                    validators: {
                        notEmpty: {
                            message: '请输入联系人'
                        }
                    }
                },
                linkPhone: {
                    validators: {
                        notEmpty: {
                            message: '请输入联系人电话'
                        },
                        regexp: {
                            regexp: /^[0-9]*$/,
                            message: '请输入正确电话号码'
                        }
                    }
                },
                principal: {
                    validators: {
                        notEmpty: {
                            message: '请输入负责人'
                        }
                    }
                },
                principalPhone: {
                    validators: {
                        notEmpty: {
                            message: '请输入负责人电话'
                        },
                        regexp: {
                            regexp: /^[0-9]*$/,
                            message: '请输入正确电话号码'
                        }
                    }
                },
                remark: {
                    validators: {}
                },
            }
        }).off('success.form.bv').on('success.form.bv', function (e) {

            $('#saveModal').modal('show');
            e.preventDefault();
            var $form = $(e.target);
            $('#saveTrue').click(function () {
                $.ajax({
                    url: '/organization/save',
                    type: 'POST',
                    data: $form.serialize(),
                    success: function (data) {
                        if (data.status == 200) {
                            if (data.data.parent) {
                                $('#secondManageRender' + data.data.id).text(data.data.orgName)
                            } else {
                                $('#firstManageRender' + data.data.id + '>a>span').eq(0).text(data.data.orgName)
                            }
                        } else {
                            alert(data.message);
                        }
                    }
                });
            });
            $('#saveCancel').click(function () {
                $('#saveModal').modal('hide');
            });
        });
    })
</script>
<script th:inline="javascript">
//debugger;
	var orgid = [[${org.id}]];
	function orgDevList () {
	   		$.ajax({
		         url: "/orgdev/list/"+orgid,
		         type: 'POST',
		         dataType: 'html',
		         data: {
		        	 "address":''
		         },
		         success: function(data) {
	 				$("#orgList").html(data);
	          	},
				error: function (error) {
					alert(error);
				}
	       	});
	}
</script>
</body>
</html>
